package com.allen.study.application.api;

import com.allen.study.application.api.request.ApprovalRecordCreateRequest;
import com.allen.study.application.api.request.ApprovalRecordQueryRequest;
import com.allen.study.application.api.request.ApprovalRecordUpdateRequest;
import com.allen.study.application.api.response.ApprovalRecordQueryResponse;
import com.allen.study.application.api.response.ApprovalRecordResponse;
import com.allen.study.application.service.ApprovalRecordAppService;
import com.allen.study.common.base.ApiPageResponse;
import com.allen.study.common.base.ApiResponse;
import com.allen.study.common.base.Pagination;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;

/**
 * 审批记录表接口
 *
 * @author AllenSun
 * @since 2025-04-23 20:46
 */
@RequestMapping(value = "/4.2.0/approvalrecord")
@RestController
@AllArgsConstructor
@Tag(name = "审批记录表接口", description = "审批记录表接口")
public class ApprovalRecordApi {

    /**
     * 审批记录表应用服务
     */
    private final ApprovalRecordAppService approvalRecordAppService;

    /**
     * 创建审批记录表
     *
     * @param createRequest 审批记录表创建对象
     * @return 响应结果
     */
    @PostMapping
    @Operation(summary = "创建审批记录表", description = "创建审批记录表")
    public ApiResponse<Void> create(@RequestBody @Valid ApprovalRecordCreateRequest createRequest) {
        return approvalRecordAppService.create(createRequest);
    }

    /**
     * 根据主键删除审批记录表
     *
     * @param approvalRecordId 审批记录表主键
     * @return 响应结果
     */
    @DeleteMapping(value = "/{approval_record_id}")
    @Operation(summary = "根据主键删除审批记录表", description = "根据主键删除审批记录表")
    public ApiResponse<Void> deleteById(@PathVariable(name = "approval_record_id") Long approvalRecordId) {
        return approvalRecordAppService.deleteById(approvalRecordId);
    }

    /**
     * 根据主键更新审批记录表
     *
     * @param approvalRecordId 审批记录表主键
     * @param updateRequest 审批记录表更新对象
     * @return 响应结果
     */
    @PutMapping(value = "/{approval_record_id}")
    @Operation(summary = "根据主键更新审批记录表", description = "根据主键更新审批记录表")
    public ApiResponse<Void> updateById(@PathVariable(name = "approval_record_id") Long approvalRecordId,
            @RequestBody @Valid ApprovalRecordUpdateRequest updateRequest) {
        return approvalRecordAppService.updateById(approvalRecordId, updateRequest);
    }

    /**
     * 根据主键查询审批记录表详情
     *
     * @param approvalRecordId 审批记录表主键
     * @return 响应结果
     */
    @GetMapping(value = "/{approval_record_id}")
    @Operation(summary = "根据主键查询审批记录表详情", description = "根据主键查询审批记录表详情")
    public ApiResponse<ApprovalRecordResponse> queryById(@PathVariable(name = "approval_record_id") Long approvalRecordId) {
        return approvalRecordAppService.queryById(approvalRecordId);
    }

    /**
     * 分页查询审批记录表
     *
     * @param pagination   分页
     * @param queryRequest 审批记录表查询对象
     * @return 响应结果
     */
    @GetMapping
    @Operation(summary = "分页查询审批记录表", description = "分页查询审批记录表")
    public ApiPageResponse<ApprovalRecordQueryResponse> query(@Valid Pagination pagination, @Valid ApprovalRecordQueryRequest queryRequest) {
        return approvalRecordAppService.query(pagination, queryRequest);
    }
}
